#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

bool predictTheWinner(vector<int>& nums) {
    int n = nums.size();
    auto dfs = [&](auto&& dfs, int l, int r, int turn)->int {
        if (l == r)
            return nums[l] * turn;

        int begin = nums[l] * turn + dfs(dfs, l + 1, r, -turn);
        int end = nums[r] * turn + dfs(dfs, l, r - 1, -turn);
        return max(begin * turn, end * turn) * turn;
    };

    return dfs(dfs, 0, n - 1, 1) >= 0;
}